locals {
  malware_subnet_ids = [
    "${var.attacker_subnet_id}",
    "${var.target_subnet_id}",
  ]
}

resource "aws_instance" "flarevm-win7" {
  count         = "${var.docker_ct}"
  ami           = "${data.aws_ami.flare.id}"
  instance_type = "t2.xlarge"
  subnet_id               = "${element(local.malware_subnet_ids, count.index)}"
  vpc_security_group_ids  = ["${aws_security_group.malware.id}"]
  key_name                = "${aws_key_pair.circleci_key.key_name}"
  root_block_device {
    delete_on_termination = true
    volume_size           = 150
  }
  tags = {
    Name        = "flarevm-win7-${count.index}"
    Environment = "${var.environment}"
    Terraform   = "True"
    Auto-Off = "True",
    Auto-Delete = "True"
  }
}


resource "aws_instance" "cuckoo_guest" {
  count         = "${var.docker_ct}"
  ami           = "${data.aws_ami.win7.id}"
  instance_type = "${var.instance_type_win}"
  subnet_id               = "${element(local.malware_subnet_ids, count.index)}"
  vpc_security_group_ids  = ["${aws_security_group.malware.id}"]
  key_name                = "${aws_key_pair.circleci_key.key_name}"
  root_block_device {
    delete_on_termination = true
    volume_size           = 150
  }
  tags = {
    Name        = "cuckoo-guest-win7-${count.index}"
    Environment = "${var.environment}"
    Terraform   = "True"
    Auto-Off = "True",
    Auto-Delete = "True"

  }
}

resource "aws_instance" "cuckoo-host-ubuntu" {
  count         = "${var.docker_ct}"
  ami = "${data.aws_ami.cuckoo-host.id}"
  instance_type = "${var.instance_type_kali}"
  subnet_id = "${element(local.malware_subnet_ids, count.index)}"
  key_name = "${aws_key_pair.circleci_key.key_name}"
  vpc_security_group_ids = ["${aws_security_group.malware.id}"]

  tags = {
//    todo: tag standardization
    Name = "cuckoo-host-ubuntu1804"
    Auto-Off = "True",
    Auto-Delete = "True"
    Terraform = "True"
    Environment = "${var.environment}"
  }
}


resource "aws_instance" "remnux" {
  count         = "${var.docker_ct}"
  ami = "${data.aws_ami.remnux.id}"
  instance_type = "${var.instance_type_kali}"
  subnet_id = "${element(local.malware_subnet_ids, count.index)}"
  key_name = "${aws_key_pair.circleci_key.key_name}"
  vpc_security_group_ids = ["${aws_security_group.malware.id}"]
  user_data = "${file("../../modules/infrastructure/cloud-init/remnux.ssh.enable.yml")}"
  tags = {
    //    todo: tag standardization
    Name = "remnux-6.0"
    Auto-Off = "True",
    Auto-Delete = "True"
    Terraform = "True"
    Environment = "${var.environment}"
  }
}